import type { App } from 'vue'
import copy from './modules/copy'
import waterMarker from './modules/waterMarker'
import draggable from './modules/draggable'
import debounce from './modules/debounce'
import throttle from './modules/throttle'
import longpress from './modules/longpress'
import timer from './modules/timer'

const directivesList: any = {
	// Custom directives
	copy,
	waterMarker,
	draggable,
	debounce,
	throttle,
	longpress,
	timer,
}

export default {
	install(app: App<Element>) {
		Object.keys(directivesList).forEach((key) => {
			// 注册所有自定义指令
			app.directive(key, directivesList[key])
		})
		app.directive('focus', {
			created() {},
			beforeMount() {},
			mounted(el: HTMLElement) {
				el.focus()
			},
			beforeUpdate() {},
			updated() {
				console.log('指令更新')
			},
			beforeUnmount() {},
			unmounted() {
				console.log('指令卸载')
			},
		})
		app.directive('red', {
			mounted(el: HTMLElement) {
				el.style.color = 'red'
			},
		})
	},
}
